<?php
// +----------------------------------------------------------------------
// | 有理想的地方，地狱都是天堂。
// +----------------------------------------------------------------------
// | Copyright @ df81.com 版权所有
// +----------------------------------------------------------------------
// | 作者: 南国老符 邮箱：1062129401@qq.com
// +----------------------------------------------------------------------

namespace app\api\model\v1;
use think\Model;
use think\facade\Db;

class Language extends Model{
    /**列表
    * signid 1启用，0不启用
    * keyword 关键词
    * order 排序
    */
	static function index($signid = 1, $keyword = '', $order = 'sequence desc'){
		$keyword = trim($keyword); $pageParam = array('lang'=>$lang);
        // 是否启用
		if(in_array($signid,array('0','1'))){
		    $where[] = ['signid','=',$signid];
		    $pageParam += array('lang'=>$lang);
		}
		// 关键词查找
		if(!empty($keyword)){
		    $where[] = ['admintitle|viewtitle','like',$keyword];
		    $pageParam += array('keyword'=>$keyword);
		}

		$rs = Db::name('language')->where($where)->order($order)
            ->paginate([
                'list_rows'=> 20,
                'query'=> $pageParam,
            ]);
        $rs = $rs->each(function($item, $key){
            if(config('global.url.bind_lang') == 1){
                $domainArray = config('app.domain_bind'); $default_lang = config('lang.default_lang');
                foreach ($domainArray as $domainKey => $domain){
                    if($domain == $item['mulu']){
                        if($item['mulu'] == $default_lang){
                            if(substr_count($domainKey,'.') == 1) $url = request()->scheme().'://'.$domainKey.'/';
                            if(strpos($domainKey,'www.') !== false) $url = request()->scheme().'://'.$domainKey.'/';
                        }else{
                            $url = request()->scheme().'://'.$domainKey.'/';
                        }
                    }
                }
            }else{
                $url = '/'.$item['mulu'].'/';
            }
            $item['url'] = $url;
            return $item;
        });
		return $rs;
	}
}